/*
 *  Copyright (C) 2010  Noxious Productions
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef __BUTTON_H__
#define __BUTTON_H__

#include <SFML/Graphics.hpp>
#include <string>
using namespace std;

/**
 *  Simple push button. Has three states: normal, hover and pressed. Can be any size and hav any font.
 */

class Button
{
public:

    /**
     *  Constructor.
     */
    Button();

    /**
     *  Destructor.
     */
    ~Button();

    /**
     *  Sets the parent sf::RenderWindow. This is needed to draw the button without returning it's sf::Sprite.
     *  @param renderWindow Parent sf::RenderWindow.
     */
    void SetParent(sf::RenderWindow * renderWindow);

    /**
     *  Draws the button on the window.
     */
    void Draw();

    /**
     *  Sets the sf::Image of the normal state. This is the only one that really should be called before displaying the button.
     *  @param fileName Path to the image file.
     *  @return Returns true if successful.
     */
    bool SetImageNormal(const string &fileName);

    /**
     *  Sets the sf::Image of the hover state.
     *  @param fileName Path to the image file.
     *  @return Returns true if successful.
     */
    bool SetImageHover(const string &fileName);

    /**
     *  Sets the sf::Image of the pressed state.
     *  @param fileName Path to the image file.
     *  @return Returns true if successful.
     */
    bool SetImagePressed(const string &fileName);

    /**
     *  Checks the SFML events for mouse key pressed etc. Should be called once in a loop.
     *  @param Event The sf::Event from the main loop.
     *  @return Returns true if the button was pressed.
     */
    bool CheckEvents(sf::Event &Event);

    /**
     *  Sets the text of the button if needed.
     *  @param Text The text.
     *  @param Font The font of the text.
     *  @param size Size of the text.
     *  @return Returns true if successful.
     */
    bool SetText(const string &Text, const sf::Font &Font, float size);

    /**
     *  Sets the position of the button.
     *  @param X New X coord of the button.
     *  @param Y New Y coord of the button.
     */
    void SetPosition(float X, float Y);

private:

    enum State
    {
        Normal,
        Hover,
        Pressed
    } state;

    void SetState(State s);
    void CenterText();
    
    sf::RenderWindow * parent;
    sf::Image * imageNormal;
    sf::Image * imageHover;
    sf::Image * imagePressed;

    sf::String * text;

    sf::Sprite sprite;
    
};

#endif
